package 剑指offer;
//0729
//作者：jyd
//        链接：https://leetcode-cn.com/problems/cong-wei-dao-tou-da-yin-lian-biao-lcof/solution/mian-shi-ti-06-cong-wei-dao-tou-da-yin-lian-biao-d/
//        来源：力扣（LeetCode）
//        著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。
import java.util.ArrayList;
 class ListNode {
      int val;
      ListNode next;
      ListNode(int x) { val = x; }
  }
public class 从尾到头打印链表 {

        ArrayList<Integer> tmp = new ArrayList<Integer>();
        public int[] reversePrint(ListNode head) {
            recur(head);
            int[] res = new int[tmp.size()];
            for(int i = 0; i < res.length; i++)
                res[i] = tmp.get(i);
            return res;
        }
        void recur(ListNode head) {
            if(head == null) return;
            recur(head.next);
            tmp.add(head.val);
        }
    }


//class Solution {
//    public int[] reversePrint(ListNode head) {
//        LinkedList<Integer> stack = new LinkedList<Integer>();
//        while(head != null) {
//            stack.addLast(head.val);
//            head = head.next;
//        }
//        int[] res = new int[stack.size()];
//        for(int i = 0; i < res.length; i++)
//            res[i] = stack.removeLast();
//        return res;
//    }
//}

